package com.zx.cloud.security.controller;

import com.alibaba.druid.util.StringUtils;
import com.zx.cloud.common.result.R;
import com.zx.cloud.security.service.impl.HdfsService;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhaoxuan
 * @date 2021-06-18 18:33
 **/
@RestController
@RequestMapping("/hdfs")
@Slf4j
public class HdfsController {
    /**
     * 创建文件
     * @param path
     * @return
     * @throws Exception
     */
    @PostMapping("/createFile")
    public R<?> createFile(@RequestParam("path") String path, @RequestParam("file") MultipartFile file)
            throws Exception {
        if (StringUtils.isEmpty(path) || null == file.getBytes()) {
            return R.error();
        }
        HdfsService.createFile(path, file);
        return R.ok();
    }

}
